package com.duolebo.uteped_sdk.model;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;

import com.yc.nadalsdk.bean.StressData;

import java.util.ArrayList;

/**
 * @Author: wudapeng
 * @Date: 2023/12/20 15:01
 * @Description:
 */
public class StressModel extends BaseModel {

    private String calendarTime;
    private String calendar;
    private int time;
    private int level;
    private int pressureValue;

    public String getCalendarTime() {
        return calendarTime;
    }

    public void setCalendarTime(String calendarTime) {
        this.calendarTime = calendarTime;
    }

    public String getCalendar() {
        return calendar;
    }

    public void setCalendar(String calendar) {
        this.calendar = calendar;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getPressureValue() {
        return pressureValue;
    }

    public void setPressureValue(int pressureValue) {
        this.pressureValue = pressureValue;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getLevel() {
        return level;
    }

    public StressModel() {
    }

    /**
     * BaseModel
     *
     * @param model model
     */
    StressModel(BaseModel model) {
        super(model);
    }

    public StressModel(StressData data) {
        this.calendarTime = data.getCalendarTime();
        this.calendar = data.getCalendar();
        this.time = data.getTime();
        this.pressureValue = data.getPressureValue();

        setPressureLevel();
    }

    @Override
    public void writeFieldValues(ContentValues values) {
        super.writeFieldValues(values);
        values.put(StressFields.CALENDAR_TIME, calendarTime);
        values.put(StressFields.CALENDAR, calendar);
        values.put(StressFields.TIME, time);
        values.put(StressFields.LEVEL, level);
        values.put(StressFields.PRESSURE_VALUE, pressureValue);
    }

    @SuppressLint("Range")
    @Override
    public void readFieldValues(Cursor c) {
        super.readFieldValues(c);
        calendarTime = c.getString(c.getColumnIndex(StressFields.CALENDAR_TIME));
        calendar = c.getString(c.getColumnIndex(StressFields.CALENDAR));
        time = c.getInt(c.getColumnIndex(StressFields.TIME));
        level = c.getInt(c.getColumnIndex(StressFields.LEVEL));
        pressureValue = c.getInt(c.getColumnIndex(StressFields.PRESSURE_VALUE));
    }

    @Override
    public void prepareFieldDefs(ArrayList<String> fieldDefs) {
        super.prepareFieldDefs(fieldDefs);
        fieldDefs.add(StressFields.CALENDAR_TIME + FIELD_TYPE_TEXT);
        fieldDefs.add(StressFields.CALENDAR + FIELD_TYPE_TEXT);
        fieldDefs.add(StressFields.TIME + FIELD_TYPE_INTEGER);
        fieldDefs.add(StressFields.LEVEL + FIELD_TYPE_INTEGER);
        fieldDefs.add(StressFields.PRESSURE_VALUE + FIELD_TYPE_INTEGER);
    }

    public void setPressureLevel() {
        if (pressureValue > 79) {
            setLevel(4);
        } else if (pressureValue > 59) {
            setLevel(3);
        } else if (pressureValue > 29) {
            setLevel(2);
        } else {
            setLevel(1);
        }
    }

    public static class StressFields implements Fields {
        public static final String CALENDAR_TIME = "calendar_time";
        public static final String CALENDAR = "calendar";
        public static final String TIME = "time";
        public static final String LEVEL = "level";
        public static final String PRESSURE_VALUE = "pressure_value";
    }

}
